package com.kungfu.controller;

import com.google.gson.Gson;
import com.kungfu.entity.ReceiptItem;
import com.kungfu.entity.request.InpatientChargeItemData;
import com.kungfu.entity.request.InpatientChargeTotalData;
import com.kungfu.entity.request.ReadyToChargeRequest;
import com.kungfu.service.ReceiptItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class TestController extends BaseController {
    @Autowired
    private ReceiptItemService receiptItemService;
    @PostMapping("/testData")
    public String test(@RequestBody String data) {
        Gson gson = new Gson();
        ReadyToChargeRequest request = gson.fromJson(data, ReadyToChargeRequest.class);
        System.out.println(request.getSJDFEE());
        InpatientChargeTotalData targetItem = gson.fromJson(gson.toJson(request.getRESULTSET()), InpatientChargeTotalData.class);
        BigDecimal sum = BigDecimal.ZERO;
        for (InpatientChargeItemData itemData :
                targetItem.getResultSet()) {
            System.out.println(itemData.getJE());
            BigDecimal je = new BigDecimal(itemData.getJE());
            sum = sum.add(je.multiply(new BigDecimal(100)));
        }
        System.out.println(sum);
        BigDecimal sjdfee = new BigDecimal(request.getSJDFEE());
        sjdfee = sjdfee.multiply(new BigDecimal(100));
        return "SJDFEE:" + sjdfee.intValue() + " sum:" + sum.intValue();
    }
    @GetMapping("/testInsert")
    public String test1(){
        System.out.println("-----------------------");
        List<ReceiptItem> list = new ArrayList<>();
        for(int i=0;i<5;i++){
            ReceiptItem item = new ReceiptItem();
            item.setId(System.currentTimeMillis()+"");
            item.setReceiptItemCode("3333333");
            item.setReceiptItemName("测试0");
            item.setReceiptItemNum(1.0);
            item.setReceiptItemType("lx");
            item.setReceiptItemUnit("ce");
            item.setReceiptNo("123456789");
            item.setMajorCatalogues(1);
            item.setIsImp(0);
            item.setDetailId("oiioi12313");
            item.setChargeDate(new Date());
            item.setStatus(0);
            item.setFee(100);
            item.setUnitFee(100);
            item.setDetailNo("1222333");
            list.add(item);
        }
      return "结果："+ receiptItemService.insertList(list);
    }
}
